package com.warm.pump.module.sys.dao.gen;

import java.util.List;
import java.util.Map;
import java.util.Date;
import java.math.BigDecimal;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

import com.warm.pump.frame.gen.bean.PageBean;
import com.warm.pump.frame.gen.util.TypeCast;
import com.warm.pump.frame.gen.exception.ServiceException;
import com.warm.pump.module.sys.bean.po.gen.SysRoleMenu;
import com.warm.pump.module.sys.mapper.gen.SysRoleMenuMapper;
import com.warm.pump.module.sys.bean.po.gen.SysRoleMenuExample;
@Repository
public class SysRoleMenuDao {
	// 日志对象
	private transient Log log = LogFactory.getLog(this.getClass());
	@Autowired
	private SysRoleMenuMapper sysRoleMenuMapper;

	// 增加一个后台SysRoleMenu表
	
	public boolean insert(SysRoleMenu sysRoleMenu) {
		try {
			sysRoleMenuMapper.insert(sysRoleMenu);
			log.debug("后台SysRoleMenu表增加成功");
			return true;
		} catch (Exception e) {
			log.debug("后台SysRoleMenu表增加失败");
			throw new ServiceException("后台SysRoleMenu表增加失败",e);
		}
	}
	// 增加一个后台SysRoleMenu表Selective
	
	public boolean insertSelective(SysRoleMenu sysRoleMenu) {
		try {
			sysRoleMenuMapper.insertSelective(sysRoleMenu);
			log.debug("后台SysRoleMenu表增加成功");
			return true;
		} catch (Exception e) {
			log.debug("后台SysRoleMenu表增加失败");
			throw new ServiceException("后台SysRoleMenu表增加失败",e);
		}
	}

	// 删除一个后台SysRoleMenu表
	
	public boolean deleteByPrimaryKey(Long id) {
		try{
			sysRoleMenuMapper.deleteByPrimaryKey(id);
			log.debug("后台SysRoleMenu表删除成功");
			return true;
		} catch(Exception e){
			log.debug("后台SysRoleMenu表删除失败");
			throw new ServiceException("后台SysRoleMenu表删除失败",e);
		}
	}
	// 删除一个后台SysRoleMenu表byMap
	
	public boolean deleteByMap(Map sysRoleMenuMap) {
		try{
			sysRoleMenuMapper.deleteByExample(createSysRoleMenuExample(sysRoleMenuMap,null,null));
			log.debug("后台SysRoleMenu根据Map删除成功");
			return true;
		}
		
		catch(Exception e){
			log.debug("后台SysRoleMenu根据GroupID删除失败");
			throw new ServiceException("后台SysRoleMenu根据object删除失败",e);
		}
	}
	// 修改一个后台SysRoleMenu表
	
	public boolean updateByPrimaryKey(SysRoleMenu sysRoleMenu) {
		try{
			sysRoleMenuMapper.updateByPrimaryKey(sysRoleMenu);
			log.debug("后台SysRoleMenu表修改成功");
			return true;
		}
		
		catch(Exception e){
			log.debug("后台SysRoleMenu表修改失败");
			throw new ServiceException("后台SysRoleMenu表修改失败",e);
		}
	}
	// 修改一个后台SysRoleMenu表Selective
	
	public boolean updateByPrimaryKeySelective(SysRoleMenu sysRoleMenu) {
		try{
			sysRoleMenuMapper.updateByPrimaryKeySelective(sysRoleMenu);
			log.debug("后台SysRoleMenu表修改成功");
			return true;
		}
		
		catch(Exception e){
			log.debug("后台SysRoleMenu表修改失败");
			throw new ServiceException("后台SysRoleMenu表修改失败",e);
		}
	}
	// 修改一个后台SysRoleMenu表
	
	public boolean updateByMap(SysRoleMenu sysRoleMenu,Map sysRoleMenuMap) {
		try{
			sysRoleMenuMapper.updateByExample(sysRoleMenu,createSysRoleMenuExample(sysRoleMenuMap,null,null));
			log.debug("后台批量SysRoleMenu表修改成功");
			return true;
		}
		catch(Exception e){
			log.debug("后台批量SysRoleMenu表修改失败");
			throw new ServiceException("后台SysRoleMenu表批量修改失败",e);
		}
	}
	// 修改一个后台SysRoleMenu表Selective
	
	public boolean updateByMapSelective(SysRoleMenu sysRoleMenu,Map sysRoleMenuMap) {
		try{
			sysRoleMenuMapper.updateByExampleSelective(sysRoleMenu,createSysRoleMenuExample(sysRoleMenuMap,null,null));
			log.debug("后台批量SysRoleMenu表修改成功");
			return true;
		}
		catch(Exception e){
			log.debug("后台批量SysRoleMenu表修改失败");
			throw new ServiceException("后台SysRoleMenu表批量修改失败",e);
		}
	}

	// 查询一个后台SysRoleMenu表
	
	public SysRoleMenu selectByPrimaryKey(Long id) {
		return sysRoleMenuMapper.selectByPrimaryKey(id);
	}
	
	// 查询一个后台SysRoleMenu表-根据map
	
	public SysRoleMenu selectByMap(Map sysRoleMenuMap) {
		List<SysRoleMenu> list = getListByMap(sysRoleMenuMap);
		if(list==null||list.isEmpty()){
			return null;
		}else{
			return list.get(0);
		}
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////////
	// 查询所有后台SysRoleMenu表
	
	public List<SysRoleMenu> getListByMap(Map sysRoleMenuMap) {
		
		return sysRoleMenuMapper.selectByExample(createSysRoleMenuExample(sysRoleMenuMap,null,null));
	}

	//统计后台SysRoleMenu表数量
	
	public int countTotalByMap(Map sysRoleMenuMap) {
		
		return sysRoleMenuMapper.countByExample(createSysRoleMenuExample(sysRoleMenuMap,null,null));
	}

	
	public List<SysRoleMenu> getListByMapPage(Map sysRoleMenuMap, int limitStart,
			int limitOffset) {
		
		return sysRoleMenuMapper.selectByExample(createSysRoleMenuExample(sysRoleMenuMap,limitStart,limitOffset));
	}
	
	
	public PageBean getPageBeanByMap(Map sysRoleMenuMap,int pageNo,int pageSize) {
		Integer count = countTotalByMap(sysRoleMenuMap);
		PageBean pageBean = new PageBean();
		pageBean.setCount(count);
		pageBean.setPageNo(pageNo);
		pageBean.setPageSize(pageSize);
		int limitStart = pageBean.getStartNo();
		int limitOffset = pageSize;
		pageBean.setData(sysRoleMenuMapper.selectByExample(createSysRoleMenuExample(sysRoleMenuMap,limitStart,limitOffset)));
		return pageBean;
	}
		
	private SysRoleMenuExample createSysRoleMenuExample(Map sysRoleMenuMap,Integer limitStart,Integer limitOffset){
			SysRoleMenuExample sysRoleMenuEx = new SysRoleMenuExample();
			SysRoleMenuExample.Criteria c = sysRoleMenuEx.createCriteria();
				Long id_null = TypeCast.getLong(sysRoleMenuMap.get("id_null"));
				Long id_notNull = TypeCast.getLong(sysRoleMenuMap.get("id_notNull"));
				Long id = TypeCast.getLong(sysRoleMenuMap.get("id"));
				Long id_not = TypeCast.getLong(sysRoleMenuMap.get("id_not"));
				Long id_greater = TypeCast.getLong(sysRoleMenuMap.get("id_greater"));
				Long id_greaterEqual = TypeCast.getLong(sysRoleMenuMap.get("id_greaterEqual"));
				Long id_less = TypeCast.getLong(sysRoleMenuMap.get("id_less"));
				Long id_lessEqual = TypeCast.getLong(sysRoleMenuMap.get("id_lessEqual"));
				List<Long> id_in = TypeCast.getLongList(sysRoleMenuMap.get("id_in"));
				List<Long> id_notIn = TypeCast.getLongList(sysRoleMenuMap.get("id_notIn"));
				Long id_between1 = TypeCast.getLong(sysRoleMenuMap.get("id_between1"));
				Long id_between2 = TypeCast.getLong(sysRoleMenuMap.get("id_between2"));
				Long id_notBetween1 = TypeCast.getLong(sysRoleMenuMap.get("id_notBetween1"));
				Long id_notBetween2 = TypeCast.getLong(sysRoleMenuMap.get("id_notBetween2"));
				
				if(id_null != null){
					c.andIdIsNull();
				}
				if(id_notNull != null){
					c.andIdIsNotNull();
				}
				if(id != null){
					c.andIdEqualTo(id);
				}
				if(id_not != null){
					c.andIdNotEqualTo(id_not);
				}
				if(id_greater != null){
					c.andIdGreaterThan(id_greater);
				}
				if(id_greaterEqual != null){
					c.andIdGreaterThanOrEqualTo(id_greaterEqual);
				}
				if(id_less != null){
					c.andIdLessThan(id_less);
				}
				if(id_lessEqual != null){
					c.andIdLessThanOrEqualTo(id_lessEqual);
				}
				if(id_in != null){
					c.andIdIn(id_in);
				}
				if(id_notIn != null){
					c.andIdNotIn(id_notIn);
				}
				if(id_between1 != null){
					c.andIdBetween(id_between1,id_between2);
				}
				if(id_notBetween1 != null){
					c.andIdNotBetween(id_notBetween1,id_notBetween2);
				}
				Long roleId_null = TypeCast.getLong(sysRoleMenuMap.get("roleId_null"));
				Long roleId_notNull = TypeCast.getLong(sysRoleMenuMap.get("roleId_notNull"));
				Long roleId = TypeCast.getLong(sysRoleMenuMap.get("roleId"));
				Long roleId_not = TypeCast.getLong(sysRoleMenuMap.get("roleId_not"));
				Long roleId_greater = TypeCast.getLong(sysRoleMenuMap.get("roleId_greater"));
				Long roleId_greaterEqual = TypeCast.getLong(sysRoleMenuMap.get("roleId_greaterEqual"));
				Long roleId_less = TypeCast.getLong(sysRoleMenuMap.get("roleId_less"));
				Long roleId_lessEqual = TypeCast.getLong(sysRoleMenuMap.get("roleId_lessEqual"));
				List<Long> roleId_in = TypeCast.getLongList(sysRoleMenuMap.get("roleId_in"));
				List<Long> roleId_notIn = TypeCast.getLongList(sysRoleMenuMap.get("roleId_notIn"));
				Long roleId_between1 = TypeCast.getLong(sysRoleMenuMap.get("roleId_between1"));
				Long roleId_between2 = TypeCast.getLong(sysRoleMenuMap.get("roleId_between2"));
				Long roleId_notBetween1 = TypeCast.getLong(sysRoleMenuMap.get("roleId_notBetween1"));
				Long roleId_notBetween2 = TypeCast.getLong(sysRoleMenuMap.get("roleId_notBetween2"));
				
				if(roleId_null != null){
					c.andRoleIdIsNull();
				}
				if(roleId_notNull != null){
					c.andRoleIdIsNotNull();
				}
				if(roleId != null){
					c.andRoleIdEqualTo(roleId);
				}
				if(roleId_not != null){
					c.andRoleIdNotEqualTo(roleId_not);
				}
				if(roleId_greater != null){
					c.andRoleIdGreaterThan(roleId_greater);
				}
				if(roleId_greaterEqual != null){
					c.andRoleIdGreaterThanOrEqualTo(roleId_greaterEqual);
				}
				if(roleId_less != null){
					c.andRoleIdLessThan(roleId_less);
				}
				if(roleId_lessEqual != null){
					c.andRoleIdLessThanOrEqualTo(roleId_lessEqual);
				}
				if(roleId_in != null){
					c.andRoleIdIn(roleId_in);
				}
				if(roleId_notIn != null){
					c.andRoleIdNotIn(roleId_notIn);
				}
				if(roleId_between1 != null){
					c.andRoleIdBetween(roleId_between1,roleId_between2);
				}
				if(roleId_notBetween1 != null){
					c.andRoleIdNotBetween(roleId_notBetween1,roleId_notBetween2);
				}
				Long menuId_null = TypeCast.getLong(sysRoleMenuMap.get("menuId_null"));
				Long menuId_notNull = TypeCast.getLong(sysRoleMenuMap.get("menuId_notNull"));
				Long menuId = TypeCast.getLong(sysRoleMenuMap.get("menuId"));
				Long menuId_not = TypeCast.getLong(sysRoleMenuMap.get("menuId_not"));
				Long menuId_greater = TypeCast.getLong(sysRoleMenuMap.get("menuId_greater"));
				Long menuId_greaterEqual = TypeCast.getLong(sysRoleMenuMap.get("menuId_greaterEqual"));
				Long menuId_less = TypeCast.getLong(sysRoleMenuMap.get("menuId_less"));
				Long menuId_lessEqual = TypeCast.getLong(sysRoleMenuMap.get("menuId_lessEqual"));
				List<Long> menuId_in = TypeCast.getLongList(sysRoleMenuMap.get("menuId_in"));
				List<Long> menuId_notIn = TypeCast.getLongList(sysRoleMenuMap.get("menuId_notIn"));
				Long menuId_between1 = TypeCast.getLong(sysRoleMenuMap.get("menuId_between1"));
				Long menuId_between2 = TypeCast.getLong(sysRoleMenuMap.get("menuId_between2"));
				Long menuId_notBetween1 = TypeCast.getLong(sysRoleMenuMap.get("menuId_notBetween1"));
				Long menuId_notBetween2 = TypeCast.getLong(sysRoleMenuMap.get("menuId_notBetween2"));
				
				if(menuId_null != null){
					c.andMenuIdIsNull();
				}
				if(menuId_notNull != null){
					c.andMenuIdIsNotNull();
				}
				if(menuId != null){
					c.andMenuIdEqualTo(menuId);
				}
				if(menuId_not != null){
					c.andMenuIdNotEqualTo(menuId_not);
				}
				if(menuId_greater != null){
					c.andMenuIdGreaterThan(menuId_greater);
				}
				if(menuId_greaterEqual != null){
					c.andMenuIdGreaterThanOrEqualTo(menuId_greaterEqual);
				}
				if(menuId_less != null){
					c.andMenuIdLessThan(menuId_less);
				}
				if(menuId_lessEqual != null){
					c.andMenuIdLessThanOrEqualTo(menuId_lessEqual);
				}
				if(menuId_in != null){
					c.andMenuIdIn(menuId_in);
				}
				if(menuId_notIn != null){
					c.andMenuIdNotIn(menuId_notIn);
				}
				if(menuId_between1 != null){
					c.andMenuIdBetween(menuId_between1,menuId_between2);
				}
				if(menuId_notBetween1 != null){
					c.andMenuIdNotBetween(menuId_notBetween1,menuId_notBetween2);
				}
			if(sysRoleMenuMap.get("orderBy")!=null){
				sysRoleMenuEx.setOrderByClause((String)sysRoleMenuMap.get("orderBy"));
			}
			if(limitStart != null && limitOffset != null){
				sysRoleMenuEx.setLimitStart(limitStart);
				sysRoleMenuEx.setLimitOffset(limitOffset);
			}
			
			return sysRoleMenuEx;
	}
}
